/**
 	EmailValidation class
 */
package nrb.validations.validators
{
	import mx.controls.Alert;
	import constant.*;
	
	public class EmailValidation {
		
		/**
		 	declare variables
		 */
		private var obj:Object = new Object;
		private var valid_error:String = 'valid email format';
		private var invalid_error:String = 'invalid email format';
		private var pattern:RegExp = /([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}/;
		private var language:String = 'en';
		
		/**
		 	Type: Controller
		 	@Params:none
		 	@return:none
		 	Desc: initializes variables
		 */
		public function EmailValidation(){
			obj['is_error'] = '';
			obj['error_string'] = '';
		}
		
		/**
		 	Type: Public Function
		 	@Params:lang['String'] AS String
		 	@return:void
		 	Desc: sets the type of language
		 */
		public function set_language(lang:String): void {
			language = lang;
		}
		
		/**
		 	Type: Public Function
		 	@Params:value['String'] AS String
		 	@return:Object
		 	Desc: calls isvalid function and returns object
		 */
		public function validate(value:String): Object {
			if(isvalid(value)){
				obj['is_error'] = false;
				obj['error_string'] = valid_error;
			}else{
				obj['is_error'] = true;
				obj['error_string'] = invalid_error;
			}
			return obj;
		}
		
		/**
		 	Type: Public Function
		 	@Params:value['String'] AS String
		 	@return:Boolean
		 	Desc: tests the value using regexp
		 */
		private function isvalid(value:String): Boolean {
			return pattern.test(value);
		}
		
		
		
		
	}
}